/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.robcash.apps.messagepopup.action;

import java.util.concurrent.Callable;
import org.robcash.apps.messagepopup.vo.MessageStore;

/**
 *
 * @author Rob
 */
public class MessageSourceValidator implements Callable<Boolean> {

    private MessageStore messageStore;

    /**
     * Create a new message source validator
     */
    public MessageSourceValidator() {
    }

    /**
     * Get the message store that was validated
     * @return Message store
     */
    public MessageStore getMessageStore() {
        return messageStore;
    }

    /**
     * Set the message store to validate
     * @param messageStore Message store to validate
     */
    public void setMessageStore(MessageStore messageStore) {
        this.messageStore = messageStore;
    }
    
    /**
     * Determine if the message source is valid. To do this, it will be
     * loaded.
     * @return True if the message source is valid
     * @throws java.lang.Exception Thrown if an error occurs while validating
     * the message source, or if no message source has been set
     */
    public Boolean call() throws Exception {
        if ( messageStore == null ) {
            throw new IllegalArgumentException("Validation requires that a message store be set.");
        }

        // TODO Confirm if this is sufficient
        return messageStore.isValid();
    }

}
